const $=(function(){
    const getParms=(obj)=>{
        var str="";
        for(let key in obj){
            str+=key+"="+obj[key]+"&";
        }
        return str;
    }
    const creatXHR=()=>{
        if(window.XMLHttpRequest){
            return new XMLHttpRequest();
        }
        return new ActiveXObject("Msxml2.XMLHTTP");
    }

    const get=(url,data,callback)=>{
        let xhr=creatXHR();
        xhr.open("get",url+"?"+getParms(data));
        xhr.send(null);
        xhr.onreadystatechange=function(){
            if(xhr.status==200&&xhr.readyState==4){
                if(typeof(callback)=="function"){
                    callback(xhr.response);
                }
            }
        }
    }

    const post=(url,data,callback)=>{
        let xhr=creatXHR();
        xhr.open("post",url);

        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
        xhr.responseType="json";

        xnr.send(getParms(data));
        xhr.onreadystatechange=function(){
            if(xhr.status==200&&xhr.readyState==4){
                if(typeof(callback)=="function"){
                    callback(xhr.response);
                }
            }
        }
    }
    return {
        get,
        post
    }
})()